package com.dong;

import redis.clients.jedis.Jedis;

import java.util.HashMap;

public class TestHash {
    public static void main(String[] args) {
        Jedis jedis = new Jedis("127.0.0.1", 6379);
        jedis.flushDB();
        HashMap<String, String> map = new HashMap<>();
        map.put("k1","v1");
        map.put("k2","v2");
        map.put("k3","v3");
        map.put("k4","v4");
        jedis.hmset("hash",map);
        jedis.hset("hash","k5","v5");
        System.out.println("散列hash的所有的键值对为:"+jedis.hgetAll("hash"));
        System.out.println("散列hash的所有键为:"+jedis.hkeys("hash"));
        System.out.println("散列hash的所有值为:"+jedis.hvals("hash"));
        System.out.println("将k6保存的值加上一个整数，如果k6不存在则添加k6:"+jedis.setnx("k6","v6"));
        System.out.println("散列hash的所有的键值对为:"+jedis.hgetAll("hash"));
        System.out.println("将k6保存的值加上一个整数，如果k6不存在则添加k6:"+jedis.setnx("k6","v6"));
        System.out.println("散列hash的所有的键值对为:"+jedis.hgetAll("hash"));
        System.out.println("删除一个或者多个键值对:"+jedis.hdel("hash","k1","v1","k3","v3"));
        System.out.println("散列hash的所有的键值对为:"+jedis.hgetAll("hash"));
        System.out.println("散列hash中键值对的个数:"+jedis.hlen("hash"));
        System.out.println("判断hash中是否存在k2:"+ jedis.hexists("hash","k2"));
        System.out.println("判断hash中是否存在k3:"+ jedis.hexists("hash","k3"));
        System.out.println("获取hash中的值:"+jedis.hmget("hash","k2"));
        System.out.println("获取hash中的值:"+jedis.hmget("hash","k4","k5","k2"));



    }
}
